package com.karina.visualization.chart.model;

import java.util.List;

public class CoordinateChartModel<DataType> extends ChartModel<DataType> {
	private final XAxisModel xaxis = new XAxisModel();
	private final YAxisModel yaxis = new YAxisModel();

	@Override
	public void caculatSeries() {
		List<DataType> list = getValue();

		for (DataType item : list) {
			if (seriesDescriptor == null) {
				throw new IllegalArgumentException(
						"DataDescriptor information is not set");
			}
			String xValue = seriesDescriptor.getLabel(item);

			xaxis.addCategory(xValue.toString());

		}
		List<SeriesModel> seriesList = seriesDescriptor.createSeries(list);

		double max = 0;
		// check out the series values of series list
		for (SeriesModel s : seriesList) {
			if (s instanceof HasMaxValue) {
				if (max < ((HasMaxValue) s).getMaxValue()) {
					max = ((HasMaxValue) s).getMaxValue();
				}
			}

		}

		for (SeriesModel sm : seriesList) {
			if (sm instanceof HasMaxValue) {
				((HasMaxValue) sm).setMaxValue(max);
			}
		}

		yaxis.setMaxValue(max);
		setSeies(seriesList);

	}

	public XAxisModel getXAxisModel() {
		return xaxis;
	}

	public YAxisModel getYAxisModel() {
		return yaxis;
	}
}
